package org.sanguine.plugin.timetracker.providers;

import java.util.List;

import org.sanguine.plugin.timetracker.pojo.AccountInfo;
import org.sanguine.plugin.timetracker.pojo.Project;
import org.sanguine.plugin.timetracker.pojo.Task;
import org.sanguine.plugin.timetracker.pojo.Timer;

/**
 * <p>
 * Tracker service provider
 * </p>
 * <p>
 * </p>
 * <b>Date:</b> 13.10.2014
 *
 * @author Alexey_Kuznetsov
 */
public interface TrackerServiceProvider {
    /**
     * Initialize with given credential and service endpoint
     *
     * @param endpoint
     *            service endpoint URL
     * @param userName
     *            username
     * @param password
     *            password
     * @return true if credential accepted by service, false - otherwise
     * @throws java.lang.IllegalArgumentException
     *             if some parameters is null or don't well formed
     */
    boolean initialize(String endpoint, String userName, char[] password);

    /**
     * Returns account info for initialized service
     *
     * @return AccountInfo object
     * @throws java.lang.IllegalStateException
     *             if service does not initialized properly
     */
    AccountInfo getAccountInfo();

    /**
     * Returns Provider's description
     *
     * @return Provider's description
     */
    String getDescription();

    /**
     * Get list of available projects.
     * 
     * @return projects list, it may be empty.
     * @throws java.lang.IllegalStateException
     *             if service does not initialized properly
     * @throws java.lang.RuntimeException
     *             if any error occurred
     */
    List<Project> getProjects();

    /**
     * Get list of available tasks.
     *
     * @return tasks list, it may be empty.
     * @throws java.lang.IllegalStateException
     *             if service does not initialized properly
     * @throws java.lang.RuntimeException
     *             if any error occurred
     */
    List<Task> getTasks();

    /**
     * Create and start new timer for Project/Task/Notes combination.
     *
     * @param projectId
     * @param taskId
     * @param notes
     * @return created timer
     * @throws java.lang.IllegalStateException
     *             if service does not initialized properly
     * @throws java.lang.RuntimeException
     *             if any error occurred
     */
    Timer createTimer(int projectId, int taskId, String notes);

    /**
     * Start existed timer. Service must be successful initialize before.
     * 
     * @param timerId
     *            timer Id
     * @return timer value at start moment.
     * @throws java.lang.IllegalStateException
     *             if service does not initialized properly
     * @throws java.lang.RuntimeException
     *             if any error occurred
     */
    float startTimer(int timerId);

    /**
     * Stop current timer. Service must be successful initialize before and timer started.
     *
     * @param timerId
     *            timer Id
     * @return timer value after stop.
     * @throws java.lang.IllegalStateException
     *             if service does not initialized properly or timer didn't start.
     * @throws java.lang.RuntimeException
     *             if any error occurred
     */
    float stopTimer(int timerId);

    /**
     * Get current timer value. Service must be successful initialize before and timer started.
     *
     * @param timerId
     *            timer Id
     * @return timer value at request time.
     * @throws java.lang.IllegalStateException
     *             if service does not initialized properly or timer didn't start.
     * @throws java.lang.RuntimeException
     *             if any error occurred
     */
    float getTimerValue(int timerId);

    /**
     * Returns active timer if it exist.
     *
     * @return active timer or null if timer in active phase not found
     * @throws java.lang.IllegalStateException
     *             if service does not initialized properly
     * @throws java.lang.RuntimeException
     *             if any error occurred
     */
    Timer getActiveTimer();
}
